package JZOffer;

/**
 * @author Lw中
 * @date 2021/9/5 9:47
 */
public class Jz68II {

    // Jz68 II.二叉树的最近公共祖先
    public Jz68.TreeNode lowestCommonAncestor(Jz68.TreeNode root, Jz68.TreeNode p, Jz68.TreeNode q) {
        if (root == null || p == root || q == root) return root;
        /**
         * LWZ TODO : 2021/7/26 递归语句理解模糊不清
         *
         */
        Jz68.TreeNode left = lowestCommonAncestor(root.left, p, q);
        Jz68.TreeNode right = lowestCommonAncestor(root.right, p, q);
        return left == null ? right : (right == null ? left : root);
    }

}
